import request from '@/utils/request'

// 用户认证相关接口

// 获取验证码
export function getCodeImg() {
    return request({
        url: '/captchaImage',
        headers: {
            isToken: false
        },
        method: 'get',
        timeout: 20000
    })
}

// 登录
export function login(username, password, uuid, code) {
    const data = {
        username: username,
        password: password,
        uuid: uuid,
        code: code
    }
    return request({
        url: '/login',
        method: 'post',
        data: data
    })
}

// 注册
export function register(data) {
    return request({
        url: '/register',
        method: 'post',
        data
    })
}

// 退出方法
export function logout() {
    return request({
        url: '/logout',
        method: 'post'
    })
}


// 发送短信验证码
export function sendSmsCode(phone, type) {
    return request({
        url: '/user/sms/send',
        method: 'post',
        data: { phone, type }
    })
}

// 验证短信验证码
export function verifySmsCode(phone, code) {
    return request({
        url: '/user/sms/verify',
        method: 'post',
        data: { phone, code }
    })
}

// 重置密码
export function resetPassword(data) {
    return request({
        url: '/user/password/reset',
        method: 'post',
        data
    })
}

// 修改密码
export function changePassword(data) {
    return request({
        url: '/user/password/change',
        method: 'post',
        data
    })
}

// 用户个人资料相关接口

// 获取用户详细信息
export function getUserInfo() {
    return request({
        url: '/getInfo',
        method: 'get'
    })
}

// 获取当前用户的笔记列表
export function getMyNotes(params) {
    return request({
        url: '/user/notes/me',
        method: 'get',
        params
    })
}

// 更新用户头像
export function updateAvatar(data) {
    return request({
        url: '/user/avatar/update',
        method: 'post',
        data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 更新用户个人资料
export function updateProfile(data) {
    return request({
        url: '/user/profile/update',
        method: 'post',
        data
    })
}